import json

from flask import Blueprint
from flask import request
from flask import Response

from app.comm.db import db
from app.comm.db import jsonformater
from app.comm.pub import RestEntity
from app.comm.pub import class2dict

logservice = Blueprint('log', __name__,)

@logservice.route("/rest/system/log/loginlist",methods=['POST','GET'])
def logLoginList():  
    #dict1 = json.loads(a)
    tables=db.session.execute("select info_id infoId,login_name loginName,ipaddr,login_location loginLocation,browser,os,status,msg,login_time loginTime from sys_log_login").fetchall()
    datas= [dict(r) for r in tables] 
    result=RestEntity(0,0,datas,"登陆成功！")
    return json.dumps(class2dict(result), default=jsonformater)
 
    #return json.dumps(dict1)         

@logservice.route("/rest/system/log/operlist",methods=['POST','GET'])
def logOperList():  
    #dict1 = json.loads(a)
    tables=db.session.execute("select oper_id operId,title,action,method,channel,oper_name operName,dept_name deptName,oper_url operUrl,oper_ip operIp,oper_location operLocation,oper_param operParam,status,error_msg errorMsg,oper_time operTime from sys_log_oper").fetchall()
    datas= [dict(r) for r in tables] 
    result=RestEntity(0,0,datas,"登陆成功！")
    return json.dumps(class2dict(result), default=jsonformater)
 
    #return json.dumps(dict1)    